#include "board.h"
#include "voice_module.h"
#include "queue.h"
#include "led.h"
#include "debug.h"
#include "OLED.h"

#define     ALL_NOTIFY_BIT          0xFFFFFFFF  // 接收到通知后清除所有通知位

uint8_t voice_rx_data;

typedef enum
{
    BL_CMD_LED_ON = 0x01,
    BL_CMD_LED_OFF,
    /* ...... */
}voice_cmd_t;

// led控制函数
void voice_led_on_handler(void)
{
    led_set_onoff(led1, true);
    printf("[voice] opcode: 0x%02X, ctrl open led ok\r\n",BL_CMD_LED_ON);
}

void voice_led_off_handler(void)
{
    led_set_onoff(led1, false);
    printf("[voice] opcode: 0x%02X, ctrl close led ok\r\n",BL_CMD_LED_OFF);
}

void voice_module_receive_handler(uint8_t data)
{
    voice_rx_data = data;
}

void voice_task(void* param)
{
    voice_module_init();        //语音模块初始化
    // voice_rx_func_register(voice_module_receive_handler);   //注册语音模块接收函数,由任务通知代替
    
    uint32_t rx_ulNotificationValue;
    while (1)
    {
        xTaskNotifyWait(0, ALL_NOTIFY_BIT, &rx_ulNotificationValue, portMAX_DELAY); //等待语音模块或串口接收到数据后发送数据通知值， 死等

        switch (rx_ulNotificationValue)
        {
            case BL_CMD_LED_ON:
            {
                voice_led_on_handler();
                break;
            }
            case BL_CMD_LED_OFF:
            {
                voice_led_off_handler();
                break;
            }
            default:
            {
                voice_rx_data = 0;
            }
        }
    }
}
